package ui

import (
	"clipPaste/internal/config"

	"fyne.io/fyne/v2"
	"fyne.io/fyne/v2/driver/desktop"
)

type TrayManager struct {
	app        fyne.App
	historyWin *HistoryWindow
	configMgr  *config.Manager
}

func NewTrayManager(app fyne.App, historyWin *HistoryWindow, configMgr *config.Manager) *TrayManager {
	return &TrayManager{
		app:        app,
		historyWin: historyWin,
		configMgr:  configMgr,
	}
}

func (t *TrayManager) Initialize() {
	// 创建菜单项
	menu := fyne.NewMenu("ClipPaste",
		fyne.NewMenuItem("Show History", func() {
			t.historyWin.Show()
		}),
		fyne.NewMenuItem("Settings", func() {
			t.showConfig()
		}),
		fyne.NewMenuItemSeparator(),
		fyne.NewMenuItem("Quit", func() {
			t.app.Quit()
		}),
	)

	// 设置系统托盘
	if desk, ok := t.app.(desktop.App); ok {
		desk.SetSystemTrayMenu(menu)
		// TODO: 设置图标
		// desk.SetSystemTrayIcon(resourceIconPng)
	}
}

func (t *TrayManager) showConfig() {
	// TODO: 显示配置窗口
	configWindow := t.app.NewWindow("Settings")
	// TODO: 添加配置界面内容
	configWindow.Resize(fyne.NewSize(400, 300))
	configWindow.Show()
}
